package com.hj.jwtserver.controller;

import com.hj.jwtserver.config.JwtTokenProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author : hujing
 * @Date: 2025/6/19 14:57
 * @Description:创建一个控制器来提供生成JWT令牌的API端点
 */
@RestController
@RequestMapping("/api/auth")
public class AuthController {
    
    @Autowired
    private JwtTokenProvider tokenProvider;
    
    @GetMapping("/token")
    public String generateToken(@RequestParam String username){
        return tokenProvider.generateToken(username);
    }
    
    @GetMapping("/username")
    public String getUsername(@RequestParam String token){
        return tokenProvider.getUsernameFromToken(token);
    }
}
